class Move < ActiveRecord::Base
	belongs_to :starting_position, 
		:class_name => "Position",
		:foreign_key => :starting_position_id
		
	belongs_to :ending_position,
		:class_name => "Position",
		:foreign_key => :ending_position_id

	#def initialize(*args)
	#	super()
		
		#if args.size == 1 then
		#	self.detail = args.shift
		#end
	#end

	def parse_move_string(move_string)
		self.detail = move_string
	end

	def parse_detail
		detail_hash = {}
		case self.detail
		when /(\w\d)-(\w\d)/
			detail_hash[:starting_position_coordinates] = $1
			detail_hash[:ending_position_coordinates] = $2
			detail_hash[:move_type] = :normal_move
		when /O-O/i
			detail_hash[:move_type] = :kingside_castle
		when /O-O-O/i
			detail_hash[:move_type] = :queenside_castle
		end
		detail_hash
	end

	def move_type
		parse_detail[:move_type]
	end

	def starting_position_coordinates
		parse_detail[:starting_position_coordinates]
	end

	def ending_position_coordinates
		parse_detail[:ending_position_coordinates]
	end
end
